#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>

#include "bzbfile.h"
using namespace bzbfile;


TEST_CASE( "bzbfile::path is being tested", "[single-file]" ) {

	// Empty string
	REQUIRE( bzbfile::path("") == "" );

	// Common behavior
	REQUIRE( bzbfile::path("/bin/bash") == "/bin/" );
	REQUIRE( bzbfile::path("/file") == "/" );

	//Double slash
	REQUIRE( bzbfile::path("/a1/b2//") == "/a1/b2//" );

}


TEST_CASE( "bzbfile::extension is being tested", "[single-file]" ) {

	REQUIRE( bzbfile::extension("") == "");
	REQUIRE( bzbfile::extension("/bin/bash") == "" );
	REQUIRE( bzbfile::extension("/dir/file.0.1.dat") == "dat" );
	REQUIRE( bzbfile::extension("/dir.folder/file") == "" );

}


TEST_CASE( "bzbfile::name is being tested", "[single-file]" ) {

	REQUIRE( bzbfile::name("") == "" );
	REQUIRE( bzbfile::name("/bin/bash") == "bash" );
	REQUIRE( bzbfile::name("/dir/file123.txt") == "file123.txt" );
	REQUIRE( bzbfile::name("/dir.folder/file.dat") == "file.dat" );
	REQUIRE( bzbfile::name("/dir.folder/file.0.1.dat") == "file.0.1.dat" );

}


TEST_CASE( "bzbfile::basename is being tested", "[single-file]" ) {

	REQUIRE( bzbfile::basename("") == "" );
	REQUIRE( bzbfile::basename("/bin/bash") == "bash" );
	REQUIRE( bzbfile::basename("/dir/file123.txt") == "file123" );
	REQUIRE( bzbfile::basename("/dir.folder/file.dat") == "file" );
	REQUIRE( bzbfile::basename("/dir.folder/file.0.1.dat") == "file.0.1" );

}


// NOTE: For these tests to work, the test program should be in the test/
// folder and the program should be ran from the main folder
// (as is done by 'make run_tests')


TEST_CASE( "bzbfile::exists is being tested", "[single-file]" ) {

	REQUIRE( bzbfile::exists("test/test-bzbfile") == true );

}


TEST_CASE( "bzbfile::exists_dir is being tested", "[single-file]" ) {

	REQUIRE( bzbfile::exists_dir("test/") == true );
	REQUIRE( bzbfile::exists_dir("bin/") == true );

}


TEST_CASE( "bzbfile::size is being tested", "[single-file]" ) {

	bzbfile::write("res/test", "This is a test");

	REQUIRE( bzbfile::size("res/test") == 14 );

	bzbfile::remove("res/test");

}


TEST_CASE( "bzbfile::remove is being tested", "[single-file]" ) {

	bzbfile::write("res/test", "This is a test");
	bzbfile::remove("res/test");

	REQUIRE( bzbfile::exists("res/test") == false );

}


TEST_CASE( "bzbfile::get_exe_path is being tested", "[single-file]" ) {

	REQUIRE( bzbfile::get_exe_path() != "" );

}
